package kyssion.leetcode.num51_100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class code77_组合 {
    public static void main(String[] args) {
        System.out.println(new code77_组合().combine(0, 1));
    }

    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> listList = new ArrayList<>();
        Integer[] arr = new Integer[k];
        ans(1, n, 0, k, arr, listList);
        return listList;
    }

    public void ans(int start, int end, int use, int length, Integer[] arr, List<List<Integer>> lists) {
        if (length == 0) {
            lists.add(new ArrayList<>(Arrays.asList(arr)));
            return;
        }
        for (int a = start; end - a + 1 >= length; a++) {
            arr[use] = a;
            ans(a + 1, end, use + 1, length - 1, arr, lists);
        }
    }
}
